﻿using System;
using System.Diagnostics;

using Gonte.Reflection;

namespace Gonte.Xml.Serialization
{
    /// <summary>
    /// Deserializes the DictionaryItemPrimitive object
    /// </summary>
    public class DictionaryItemPrimitiveDeserializer
        : XmlPrimitiveDeserializer
    {
        #region Constructors

        protected internal DictionaryItemPrimitiveDeserializer(Object @object)
            : base(@object)
        {
        } 

        #endregion

        #region Overridables

        protected override void OnAttribute()
        {
            DictionaryItemPrimitive itemPrimitive = (DictionaryItemPrimitive)object_;
            itemPrimitive.Key = Reader.Value;
        }

        protected override bool OnText()
        {
            DictionaryItemPrimitive itemPrimitive = (DictionaryItemPrimitive)object_;
            itemPrimitive.Value = ObjectTypeConverter.ConvertValue(Reader.Value.Trim(), itemPrimitive.Value.GetType());

            Debug.WriteLine(" <--- Exiting the deserializer for type: DictionaryItemPrimitive");

            return true; // Keep on reading
        }

        protected override bool OnEndElement()
        {
            return false; // base.OnEndElement();
        }

        #endregion

    }
}
